/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.tothgya.timetable;

import java.util.Calendar;

/**
 * This class represents a connections. A connection is an atomic journey. The
 * traveler does not have to change transportation within an atomic journey.
 * A {@link Journey} is a list of connections.
 * 
 * @author tothgya
 */
public class Connection {

    /**
     * Connection constructor
     * @param type the transportation type
     * @param start the starting stop
     * @param leave a time when the connection leaves the start stop
     * @param destination the destination stop
     * @param arrive a time when the connection arrives to the destionation stop
     */
    public Connection(String type, String start, Calendar leave, String destination, Calendar arrive) {
        this.type = type;
        this.arrive = arrive;
        this.start = start;
        this.leave = leave;
        this.destination = destination;

    }

    /**
     * The transportation type.
     */
    public String type;
    /**
     * The starting stop.
     */
    public String start;
    /**
     * The destination stop.
     */
    public String destination;
    /**
     * The time when the connection leaves the start stop.
     */
    public Calendar leave;
    /**
     * The time when the connection arrives to the destination stop.
     */
    public Calendar arrive;

    @Override
    public String toString() {
        if (arrive != null && leave != null) {
            return type + " connection from "
                    + start + "(" + java.text.DateFormat.getTimeInstance().format(leave.getTime()) + ") - "
                    + destination + "(" + java.text.DateFormat.getTimeInstance().format(arrive.getTime()) + ")";
        } else {
            return type + " connection from "
                    + start + " - "
                    + destination;
        }
    }
}
